const express = require('express');
const {singers} = require('./singers');
const app = express();

app.get('/singer/:id.html',(req, res) => {
    let {id} = req.params;
    let ans = singers.find(item => {
        if(item.id === Number(id)) {
            return true;
        }
    });
    if (!ans) {
        res.statusCode = 404;
        res.end('404 Not Found');
        return;
    }
    res.end(`
    <!DOCTYPE html>
     <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>all</title>
        </head>
        <body>
            <h2>${ans.singer_name}</h2>
            <img src="${ans.singer_pic}" alt="${ans.singer_name}">
        </body>
    </html>`
    );
});

app.listen(3000,() => {
    console.log('服务已经启动 3000端口正在监听中....');
});

